// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once

#include <cstdint>
#include <string>
#include <vector>

// Decompose a UTF-8 string into a vector of characters. This does not check for
// validity of the characters (e.g. overlong encodings, invalid codepoints), it
// just splits the string at non-continuation bytes (which is sufficient
// assuming the input is valid UTF-8).
std::vector<std::string> utf8_chars(std::string const &input);

// Check if a Unicode "character" generated by utf8_chars is valid.
bool utf8_is_valid(std::string const &input);

// Convert a Unicode codepoint to its UTF-8 representation, does not check for
// validity of the given codepoint.
std::string utf8_repr(uint32_t codepoint);

// Approximates Rust's `String::from_utf8_lossy` function, tries to decode UTF-8
// characters and replaces invalid ones with the U+FFFD replacement character.
std::string string_from_utf8_lossy(std::string const &input);
